<?php
/**
 * Created by PhpStorm.
 * User: lts
 * Date: 2018/4/27
 * Time: 17:48
 */
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$item = pdo_get('yzzc_sun_order', array('uniacid' => $_W['uniacid'], 'id' => $_GPC['id']));
$item['createtime'] = date('Y-m-d H:i:s', $item['createtime']);
if ($item['paytime']) {
    $item['paytime'] = date('Y-m-d H:i:s', $item['paytime']);
}
$item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
$item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
if ($item['usetime']) {
    $item['usetime'] = date('Y-m-d H:i:s', $item['usetime']);
}
if ($item['return_time']) {
    $item['return_time'] = date('Y-m-d H:i:s', $item['return_time']);
}
$item['carname'] = pdo_get('yzzc_sun_goods', array('id' => $item['cid']), array('name'))['name'];
$item['shopname'] = pdo_get('yzzc_sun_branch', array('id' => $item['start_shop']), array('name'))['name'];
$item['nickname'] = pdo_get('yzzc_sun_user', array('id' => $item['uid']), array('user_name'))['user_name'];
$item['shuttle_delivery'] = $item['shuttle'] = $item['shuttle_order'] = [];
if ($item['shuttle_id']) {
    $shuttle_delivery = pdo_get('yzzc_sun_shuttle_delivery', ['order_id' => $item['id']]);
    $shuttle_delivery['delivery_start_time'] = $shuttle_delivery['delivery_start_time'] ? date('Y-m-d H:i:s', $shuttle_delivery['delivery_start_time']) : '';
    $shuttle_delivery['delivery_end_time'] = $shuttle_delivery['delivery_end_time'] ? date('Y-m-d H:i:s', $shuttle_delivery['delivery_end_time']) : '';
    $shuttle_delivery['delivery_start_pic'] = $shuttle_delivery['delivery_start_pic'] ? explode(',', $shuttle_delivery['delivery_start_pic']) : [];

    $shuttle_delivery['delivery_end_pic'] = $shuttle_delivery['delivery_end_pic'] ? explode(',', $shuttle_delivery['delivery_end_pic']) : [];

    $shuttle_delivery['delivery_end_meter'] = $shuttle_delivery['delivery_end_meter'] ? explode(',', $shuttle_delivery['delivery_end_meter']) : [];

    $shuttle_delivery['delivery_start_meter'] = $shuttle_delivery['delivery_start_meter'] ? explode(',', $shuttle_delivery['delivery_start_meter']) : [];

    $item['shuttle_delivery'] = $shuttle_delivery;
    $item['shuttle'] = pdo_get('yzzc_sun_shuttle', ['id' => $item['shuttle_id']]);
    $branch_info = pdo_getall('yzzc_sun_branch', ['id in' => $item['shuttle']['branch_ids']], ['name']);
    $branch_info = implode(',', array_column($branch_info, 'name'));
    $item['shuttle']['branch_name'] = $branch_info;

    $item['shuttle_order'] = pdo_get('yzzc_sun_shuttle_income', ['order_id' => $item['id']]);
}

// var_dump($item);
$info = pdo_get('yzzc_sun_user_drive', array('uniacid' => $_W['uniacid'], 'id' => $item['driveid']));

if ($item['contract_shuttle_id']) {
    $item['contract_shuttle_name'] = pdo_fetchcolumn('select name from' . tablename('yzzc_sun_shuttle') . ' where id=' . $item['contract_shuttle_id']);
}

$xzorder = pdo_get('yzzc_sun_xzorder', array('uniacid' => $_W['uniacid'], 'ordernum' => $item['ordernum'], 'ispay' => 1));
if ($xzorder) {
    if ($xzorder['paytime']) {
        $xzorder['paytime'] = date('Y-m-d H:i:s', $xzorder['paytime']);
    }
    $xzorder['createtime'] = date('Y-m-d H:i:s', $xzorder['createtime']);

    $xzorder['start_time'] = date('Y-m-d H:i:s', $xzorder['start_time']);
    $xzorder['end_time'] = date('Y-m-d H:i:s', $xzorder['end_time']);

    if ($xzorder['return_time']) {
        $xzorder['return_time'] = date('Y-m-d H:i:s', $xzorder['return_time']);
    }
}

// var_dump($info);
include $this->template('web/orderjsy');